﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Security.Cryptography;


namespace WindowsFormsApplication9
{
    class Data
    {
        private static string connStr = "Data Source=LAPTOP-52PJRCBE;Initial Catalog=Blogs;Persist Security Info=True;User ID=sa;Password=123456";
        public static int ExecuteNoQuery(string sql)
        {
            using (SqlConnection conn=new SqlConnection(connStr))
            {
                conn.Open();
                using (SqlCommand cmd=conn.CreateCommand())
                {
                  cmd.CommandText = sql;
                  return cmd.ExecuteNonQuery();
                  
                }
            }
        }


        public static DataSet ExecuteDataSet(string sql)
        {
            using (SqlConnection xonn=new SqlConnection(connStr))
            {
                xonn.Open();
                using (SqlCommand cmd = xonn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    DataSet dataset = new DataSet();
                    adapter.Fill(dataset);
                    return dataset;
                }
            }
        }
        public static object ExecuteScalar(string sql)
        {
            using (SqlConnection conn=new SqlConnection(connStr))
            {
                conn.Open();
                using (SqlCommand cmd=conn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    return cmd.ExecuteScalar();
                }
            }
        }

    }
}
